package ysq.xyg.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import ysq.xyg.dao.BannerDao;
import ysq.xyg.model.Banner;
import ysq.xyg.service.BannerService;

import javax.annotation.Resource;
import java.util.List;

/**
 * 商品分类实现
 *
 * @author congcong tao
 * @date 2018/8/7 11:46
 */
@Service("bannerService")
public class BannerServiceImpl extends BaseServiceImpl<Banner> implements BannerService {

    @Resource
    private BannerDao bannerDao;
    @Autowired
    public void setpictureDao(BannerDao bannerDao) {
        this.baseDao = bannerDao;
    }

    @Override
    public PageInfo<Banner> pageInfo(Banner banner, int pageSize, int pageNum) {
        PageHelper.startPage(pageNum, pageSize);
        PageHelper.orderBy("order_num asc");
        // 通用Example查询
        Example example = new Example(Banner.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotEmpty(banner.getStatus())) {
            criteria.andEqualTo("status", banner.getStatus());
        }
        if (StringUtils.isNotEmpty(banner.getType())) {
            criteria.andEqualTo("type", banner.getType());
        }
        List<Banner> list = bannerDao.selectByExample(example);
        return new PageInfo<Banner>(list);
    }

    @Override
    public List<Banner> list(Banner banner) {
        // 通用Example查询
        Example example = new Example(Banner.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotEmpty(banner.getType())) {
            criteria.andEqualTo("type", banner.getType());
        }
        if (StringUtils.isNotEmpty(banner.getStatus())) {
            criteria.andEqualTo("status", banner.getStatus());
        }
        example.setOrderByClause("order_num asc");
        List<Banner> list = bannerDao.selectByExample(example);
        return list;
    }
}
